package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @BelongsProject: sky-take-out
 * @Author: song
 * @CreateTime: 2024-01-15  16:13
 * @Description: C端购物车Mapper
 * @Version: 1.0
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * @description:查询当前购物车中存在的菜品或套餐。
     * @author: song
     * @date: 2024/1/15 16:40
     * @param: [shoppingCart]
     * @return: java.util.List<com.sky.entity.ShoppingCart>
     **/
    List<ShoppingCart> list(ShoppingCart shoppingCart);
    /**
     * @description:购物车中已有商品，直接添加该商品数量即可
     * @author: song
     * @date: 2024/1/15 16:40
     * @param: [shoppingCart]
     * @return: void
     **/
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);
    /**
     * @description:向购物车中添加新的菜品或者套餐。
     * @author: song
     * @date: 2024/1/15 16:41
     * @param: [shoppingCart]
     * @return: void
     **/
    @Insert("insert into shopping_cart (name, user_id, dish_id, " +
            "setmeal_id, dish_flavor, number, amount, image, create_time) "
            + " values (#{name},#{userId},#{dishId},#{setmealId}," +
            "#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);
    /**
     * @description:根据用户id删除该用户购物车信息
     * @author: song
     * @date: 2024/1/15 16:58
     * @param: [userId]
     * @return: void
     **/
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteShoppingCart(Long userId);
}
